package com.hzxy.yiyid.web.module.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzxy.yiyid.web.common.base.BaseResult;
import com.hzxy.yiyid.web.module.controller.Dto.MouthDto;
import com.hzxy.yiyid.web.module.controller.vo.VegeFruitVo;
import com.hzxy.yiyid.web.module.repository.MouthMapper;
import com.hzxy.yiyid.web.module.repository.entity.Mouth;
import com.hzxy.yiyid.web.module.repository.entity.NourishmentFunction;
import com.hzxy.yiyid.web.module.repository.entity.VegetableFruit;
import com.hzxy.yiyid.web.module.service.MouthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class MouthServiceImpl extends ServiceImpl<MouthMapper,Mouth> implements MouthService {

    @Autowired
    private MouthMapper mapper;

    @Override
    public VegeFruitVo getAllByMouth(MouthDto mouthDto) {

        List<VegetableFruit> vegetableFruits = mapper.selectBymouth(mouthDto.getMouth());
        List<VegetableFruit> fruitList = new ArrayList<>();
        List<VegetableFruit> vegetableList = new ArrayList<>();

        VegeFruitVo vegeFruitVo = new VegeFruitVo();
        int vege = 0,fruit = 0;
        for (VegetableFruit vegetableFruit : vegetableFruits) {
            if(vegetableFruit.getType().equals(0)){
                fruit++;
                fruitList.add(vegetableFruit);
            }else {
                vege++;
                vegetableList.add(vegetableFruit);
            }
        }

        vegeFruitVo.setFruit(fruitList);
        vegeFruitVo.setVegetable(vegetableList);
        vegeFruitVo.setVegeTotal(vege);
        vegeFruitVo.setFruiTotal(fruit);
        return vegeFruitVo;
    }

    @Override
    public BaseResult<?> getDetailsInfoById(Integer id) {
        //通过拿到的果蔬id查找详细信息

        NourishmentFunction nourishmentFunction = mapper.selectDetatilsById(id);

        return BaseResult.success(nourishmentFunction);
    }
}
